/**
 * WeeShop 声明
 * ===========================================================
 * 网站： https://www.darlang.com
 * 标题： ECShop 小程序「weeshop 」- 基于 ECShop 为后台系统开发的非官方微信商城小程序
 * 链接： https://www.darlang.com/?p=709
 * 说明： 源码已开源并遵循 Apache 2.0 协议，你有权利进行任何修改，但请保留出处，请不要删除该注释。
 * ==========================================================
 * Copyright 2019 darlang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ===========================================================
 */

// detail.js
import {PNT,setNavBarTitle,showToast,pushPagePath,formatTime} from "../../../../utils/utils";
import { ReturnDetail} from "../../../../utils/apis";
import {PROMOS_TYPE} from '../../../../utils/status';

Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    orderDetail: '',
    orderStatus: ['等待买家付款','等待卖家发货','等待买家收货','交易成功','交易成功','交易取消'],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opt) {
    setNavBarTitle(PNT.order.detail);
    this.loginModal = this.selectComponent("#login-modal");
    if (!opt.orderId) {
      showToast('订单id异常','warning');
      return false;
    }
    var info = wx.getStorageSync('userInfo');
    this.setData({
      ret_id: parseInt(opt.orderId),
      info:info,
    });
    this.getOrderInfo();
  },

  /**
   * 页面跳转
   * @author darlang
   */
  pushPath(e) {
    const items = e.currentTarget.dataset;
    const pathData = [
      {type: 'goods',path: '/pages/goods/detail/detail?id=' + items.id},
      {type: 'comment',path: '/pages/member/comment/add/add?orderId=' + items.id},
      {type: 'payment',path: '/pages/shopping/payment/payment?orderId=' + items.id},
      // {type: 'shipping',path: '/pages/member/order/shipping/index?id'},
    ];
    pushPagePath(e,pathData);
  },


  /**
   * 登录回调
   * @author darlang
   */
  loginCallback(cb) {
    if (cb.detail.type === 'success') {
      this.reInitData();
    }
  },

  /**
   * 获取订单信息
   * @author darlang
   */
  getOrderInfo() {
    wx.showLoading({title: '加载中...',mask: true});
    var data = {};
    data.user_id = this.data.info.user_id;
    data.ret_id = this.data.ret_id;
    ReturnDetail(data).then((res) => {
      if(res.error_code == 10000){
        this.setData({
          info:res.data[0]
        })
      }
    });
  },

  /**
   * 重新获取
   * @author darlang
   */
  reInitData() {
    this.setData({
      orderDetail: ''
    });
    this.getOrderInfo();
    this.getCancelReason();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: "#ec5151",
      animation: {
        duration: 300,
        timingFunc: "linear"
      }
    });
    // this.reInitData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.reInitData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
});